home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
win_u_z
/
xlock_dv.zip
/
SOURCES.ZIP
/
PASSCOMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-01
|
2KB
|
96 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
This function returns a pointer to the passed-in user's
encrypted password.
*/
char *getpasswd(char *user,char *pwfile)
{
FILE *fp;
char line[80];
char name[80];
char password[80];
char *p=NULL;
int count=0;
if ((fp=fopen(pwfile,"r")) == NULL)
{
printf("ERROR: Unable to open password file: \"%s\"",pwfile);
exit(-1);
}
else
{
while (!feof(fp))
{
if (fgets(line,80,fp) != NULL)
{
p=line;
count=0;
while ((*p != ':') && (*p != NULL))
{p++ ; count++;}
strncpy(name,line,count);
name[count]=NULL;
if (!strcmp(name,user))
{ /* Our guy? */
p++; /* skip : */
count=strlen(p)-1;
strncpy(password,p,count);
password[count]=NULL;
return(password);
}
/*
printf("\tScanned N=\"%s\", PW=\"%s\" count=%d\n",name,password,count);
*/
}
}
}
}
/*
************************************************************************
*
* Password encryption routine largely stolen from:
* NCSA Telpass - edit password files for NCSA Telnet.
* Tim Krauskopf 6/88
************************************************************************
*/
/****************************************************************************/
/* Scompass
* compute and check the encrypted password
*/
char *Sencompass(char *cleartext,char *encrypt)
{
int i,ck;
char *p,c,*en,*ps;
ck=0;
en=encrypt;
p=cleartext;
ps=cleartext;
while(*p) /* checksum the string */
ck+=*p++;
c=(char) ck;
for(i=0; i<10; i++) {
*en=(char) (((*ps ^ c)|32)&127); /* XOR with checksum */
if(*ps)
ps++;
else
c++; /* to hide length */
en++;
}
*en=0;
return(encrypt);
}